<template>
  <page-container  :isback="true" :base-tab="1" :shownav="true" navtitle="发表活动感言" :istabbox="false">
    <view class="root-container form-root">
      <view class="form-container">
        <u-form labelWidth="120" labelPosition="left" :model="formData" :rules="rules" ref="hagdonGatherForm">
          <u-form-item label="感言" borderBottom prop="dynamicContent">
            <u-textarea autoHeight maxlength="500" :count="true" v-model="formData.dynamicContent"
                         placeholder="请输入内容"></u-textarea>
          </u-form-item>
          <u-form-item label="添加图片" borderBottom prop="img">
            <upload-img @submit="setImg"></upload-img>
          </u-form-item>
        </u-form>
      </view>
      <view class="button-container">
        <u-button class="submit-style button" text="提 交" @click="submit"></u-button>
      </view>
      <u-loading-page :loading="loading"></u-loading-page>
    </view>
  </page-container>
</template>

<script>
import uploadImg from '@/components/uploadImg.vue'
import {getQueryHeaders, requestGet, requestPost} from "@/util/means/request";
import {GET_SUGGEST_DEFAULT_FORM_DATA, QUERY_ALLOW_SELECT_SUGGEST_TYPE, SUBMIT_SUGGEST} from "@/api/suggestion";
import bottomPopup from "@/components/bottomPopup.vue";
import ChooseMainRepresentative from "@/components/chooseMainRepresentative.vue";
import {baseMixins} from "@/util/baseMixins";
import {successPagePath} from "@/util/publicConfig";

export default {
  mixins: [baseMixins],
  components: {
    uploadImg,
    bottomPopup,
    ChooseMainRepresentative
  },
  data() {
    return {
      loading: false,
      formData: {
        activityId:'',
        // 	感言
        dynamicContent: "",
        // 	图片
        dynamicPicsArr: [],
      },
      rules: {
        dynamicContent: {
          required: true,
          message: '请输入感言',
          trigger: ['blur', 'change']
        },
      },
    }
  },
  onLoad(params) {
    this.formData.activityId= params.activityId
  },
  methods: {

    setImg(img) {
      this.formData.dynamicPicsArr = img.map(item => item.url)
    },
    submit() {
      this.loading = true;
      let owner = this
      this.$refs.hagdonGatherForm.validate().then(res => {
        requestPost({url: '/activity/publishActivity', data: owner.formData, header: getQueryHeaders()}).then(res => {
          uni.$u.toast('添加成功');
          owner.redirectToPage(successPagePath)
        }).finally(() => {
          owner.loading = false
        })
      }).catch(errors => {
        owner.loading = false
        uni.$u.toast('校验失败')
      })
    },
  },
}
</script>

<style lang="scss">
::v-deep .u-radio {
  margin-right: 30rpx;
}
</style>
